 package com.huawei.push.controller;
 
 import com.huawei.push.service.AuthCodeService;
 import java.io.IOException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 @Controller
 public class ThymeleafAuthCodeController {
   private final Logger log = LoggerFactory.getLogger(com.huawei.push.controller.ThymeleafAuthCodeController.class);
   
   @Autowired
   private AuthCodeService auhCodeService;
   
   @RequestMapping({"/auth"})
   public String toAuthCodePage() {
     return "code/active";
   }
   
   @RequestMapping(value = {"/auth/code"}, method = {RequestMethod.POST})
   @ResponseBody
   public String getAuthCode(String type, String license) throws IOException {
     String url;
     if ("active".equals(type)) {
       url = "https://mkt.myhuaweicloud.com/api/mkp-openapi-public/global/v2/license/activate";
     } else if ("query".equals(type)) {
       url = "https://mkt.myhuaweicloud.com/api/mkp-openapi-public/global/v2/license/heartbeat";
     } else {
       throw new IllegalArgumentException("Invalid type: " + type);
     } 
     return this.auhCodeService.authCode(url, license);
   }
 }

